package com.sdgakj.repository;

import com.sdgakj.entity.FeedMsg;
import com.sdgakj.entity.Person;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.List;

/**
 * Created by 鲁俊杰 on 2017/4/28.
 */
public class PersonDaoImpl {

    @PersistenceContext
    private EntityManager em;

    List<Person> getPersonsByFId(Long fId,Integer page,Integer pageSize){

        StringBuffer sql = new StringBuffer();
        sql.append("select * from person t where 1=1 ");
        if (fId!=null){
            sql.append("and t.family_id = :familyId  ");
        }
        sql.append("order by t1.id desc ");
        sql.append("limit :page, :rows ");

        Query q = em.createNativeQuery(sql.toString(), Person.class);
        if(page != null&&page>=1) {
            q.setParameter("page", (page-1)*pageSize);
        }else {
            q.setParameter("page", 1);
        }
        if(pageSize != null) {
            q.setParameter("rows", pageSize);
        }

        return q.getResultList();
    }


}
